home *** CD-ROM | disk | FTP | other *** search
- { nomulti.pas -- Prevent multiple application instances }
-
- program NoMulti;
-
- uses WinTypes, WinProcs, WObjects;
-
- type
-
- MultiApplication = object(TApplication)
- FirstInstance: Boolean;
- constructor Init(AName: PChar);
- procedure InitMainWindow; virtual;
- procedure InitApplication; virtual;
- end;
-
- {- Initialize firstInstance data field }
- constructor MultiApplication.Init(AName: PChar);
- begin
- TApplication.Init(AName);
- FirstInstance := false
- end;
-
- {- Called to initialize first instance only }
- procedure MultiApplication.InitApplication;
- begin
- FirstInstance := true
- end;
-
- {- Initialize the application's window }
- procedure MultiApplication.InitMainWindow;
- begin
- if FirstInstance then
- MainWindow:= New(PWindow, Init(nil, 'First Instance'))
- else begin
- MessageBox(0, 'Multiple Instances Not Allowed',
- 'Application Error', mb_TaskModal or mb_IconExclamation);
- Halt(0)
- end
- end;
-
- var
-
- MultiApp: MultiApplication;
-
- begin
- MultiApp.Init('Multi');
- MultiApp.Run;
- MultiApp.Done
- end.
-
-
- { --------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 1/24/1991
- ------------------------------------------------------------- }
-
-